mod context;
mod ir;
mod lang_ir_gen;
mod source_gen;

use stencil_mir::MirModule;

use stencil_codegen::{CodeBuffer, CodegenBackend, Error};

/// Python code generator.
pub struct PythonCg;

impl CodegenBackend for PythonCg {
    type LangIrModule = ir::PyModule;

    fn get_indent(&self) -> String {
        "    ".to_owned()
    }

    fn get_comment_prefix(&self) -> String {
        "# ".to_owned()
    }

    fn get_comment_suffix(&self) -> Option<String> {
        None
    }

    fn convert_mir_to_lir(&self, common_module: &MirModule) -> Result<Self::LangIrModule, Error> {
        lang_ir_gen::conv_module(common_module)
    }

    fn generate_lang_ir(
        &self,
        lang_module: &Self::LangIrModule,
        buf: &mut CodeBuffer,
    ) -> Result<(), Error> {
        source_gen::emit_module(lang_module, buf)
    }
}
